Solving problems involving the cosine rule